from sqlalchemy import Column, Integer, String, Boolean, DateTime, Text
from sqlalchemy.sql import func
from commons.database import Base

class SellerApplication(Base):
    __tablename__ = 'seller_applications'

    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    user_id = Column(Integer, nullable=False, comment='申请人用户ID')
    company_name = Column(String(100), nullable=False, comment='公司名称')
    contact_person = Column(String(50), nullable=False, comment='联系人')
    contact_phone = Column(String(20), nullable=False, comment='联系电话')
    contact_email = Column(String(100), nullable=False, comment='联系邮箱')
    business_license = Column(String(255), comment='营业执照路径')
    description = Column(Text, comment='申请描述')
    status = Column(String(20), default='pending', comment='申请状态: pending-待审核, approved-已批准, rejected-已拒绝')
    feedback = Column(Text, comment='审核反馈')
    created_at = Column(DateTime, default=func.now(), comment='创建时间')
    updated_at = Column(DateTime, default=func.now(), onupdate=func.now(), comment='更新时间')

    def to_dict(self):
        return {
            'id': self.id,
            'user_id': self.user_id,
            'company_name': self.company_name,
            'contact_person': self.contact_person,
            'contact_phone': self.contact_phone,
            'contact_email': self.contact_email,
            'business_license': self.business_license,
            'description': self.description,
            'status': self.status,
            'feedback': self.feedback,
            'created_at': self.created_at.strftime('%Y-%m-%d %H:%M:%S') if self.created_at else None,
            'updated_at': self.updated_at.strftime('%Y-%m-%d %H:%M:%S') if self.updated_at else None
        }